﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;

namespace CubeStone.Wang.Utilities
{
    /// <summary>
    /// 哈希帮助类
    /// </summary>
    public class HashHelper
    {
        /// <summary>
        /// MD5算法
        /// </summary>
        /// <param name="strIn">需要加密的字符串</param>
        /// <returns>加密后的字符串</returns>
        public static string MD5(string strIn)
        {
            MD5 md5 = new MD5CryptoServiceProvider();
            byte[] bytesIn = UTF8Encoding.UTF8.GetBytes(strIn);
            byte[] bytesOut = md5.ComputeHash(bytesIn);
            string strOut = BitConverter.ToString(bytesOut);
            strOut = strOut.Replace("-", "");
            return strOut;
        }

        /// <summary>
        /// SHA1算法
        /// </summary>
        /// <param name="strIn">需要加密的字符串</param>
        /// <returns>加密后的字符串</returns>
        public static string SHA1(string strIn)
        {
            SHA1 sha1 = new SHA1CryptoServiceProvider();
            byte[] bytesIn = UTF8Encoding.UTF8.GetBytes(strIn);
            byte[] bytesOut = sha1.ComputeHash(bytesIn);
            string strOut = BitConverter.ToString(bytesOut);
            strOut = strOut.Replace("-", "");
            return strOut;
        }
    }
}